package com.atguigu.yygh.user.controller.admin;


import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.user.service.UserInfoService;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/userinfo")
public class AdminUserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    /**
     * 带查询条件的用户展示分页接口
     * @param pageNum 分页信息
     * @param pageSize 每页显示多少条
     * @param userInfoQueryVo 封装查询条件
     * @return 返回带查询条件的分页信息给前端
     */
    @PostMapping("/{pageNum}/{pageSize}")
    public R page(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestBody UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> page = userInfoService.getPage(pageNum, pageSize, userInfoQueryVo);
        return R.ok().data("total",page.getTotal()).data("items",page.getRecords());
    }

    /**
     * 修改用户状态
     * @param userId 传入的用户id
     * @param status 状态
     * @return
     */
    @ApiOperation(value = "锁定")
    @PutMapping("/lock/{userId}/{status}")
    public R updateStatus(
            @PathVariable Long userId,
            @PathVariable Integer status){
        userInfoService.lock(userId,status);
        return R.ok();
    }

    //查看就诊人详情信息
    @GetMapping("/show/{userId}")
    public R show(@PathVariable Long userId){
        Map<String,Object> map = userInfoService.show(userId);
        return R.ok().data(map);
    }

    //认证审批
    @PutMapping("approval/{userId}/{authStatus}")
    public R approval(@PathVariable Long userId,@PathVariable Integer authStatus) {
        userInfoService.approval(userId,authStatus);
        return R.ok();
    }
}